#ifndef __SOFT_I2C_H
#define __SOFT_I2C_H

#include "main.h"

#define DELAY_TIMES 1000

typedef struct soft_i2c_t {
	GPIO_TypeDef *SCL_Port;
	GPIO_TypeDef *SDA_Port;
	uint32_t SCL_Pin;
	uint32_t SDA_Pin;
} soft_i2c_t;

void soft_i2c_init(soft_i2c_t *i2c, GPIO_TypeDef* SCL_Port, uint32_t SCL_Pin, GPIO_TypeDef* SDA_Port, uint32_t SDA_Pin);
void soft_i2c_w_scl(soft_i2c_t *i2c, uint8_t state);
void soft_i2c_w_sda(soft_i2c_t *i2c, uint8_t state);
GPIO_PinState soft_i2c_r_sda(soft_i2c_t *i2c);
void soft_i2c_delay(uint32_t t);
void soft_i2c_start(soft_i2c_t *i2c);
void soft_i2c_stop(soft_i2c_t *i2c);
void soft_i2c_send_byte(soft_i2c_t *i2c, uint8_t data);
void soft_i2c_send_addr(soft_i2c_t *i2c, uint8_t address, uint8_t dir);
uint8_t soft_i2c_r_ack(soft_i2c_t *i2c);
void soft_i2c_w_ack(soft_i2c_t *i2c, uint8_t ack);
uint8_t soft_i2c_r_byte(soft_i2c_t *i2c);
void soft_i2c_w_reg(soft_i2c_t *i2c, uint8_t dev_addr, uint8_t reg_addr, uint8_t data);
uint8_t soft_i2c_r_reg(soft_i2c_t *i2c, uint8_t dev_addr, uint8_t reg_addr);
void soft_i2c_continuous_read(soft_i2c_t* i2c, uint8_t dev_addr, uint8_t reg_addr, uint8_t* array, uint8_t length);
#endif
